package com.llp.javaweb.service.impl;

import com.llp.javaweb.dao.UserDao;
import com.llp.javaweb.mapper.RegisterMapper;
import com.llp.javaweb.pojo.User;
import com.llp.javaweb.service.UserService;
import com.llp.javaweb.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.List;

public class UserServiceImpl implements UserService {
    UserDao userDao=new UserDao();
    public void add(User user){
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        RegisterMapper mapper = sqlSession.getMapper(RegisterMapper.class);
        //调用registerUser方法
        mapper.add(user);
        //提交事务
        sqlSession.commit();
        //释放资源
        sqlSession.close();
    }

    public User selectByName(String name){
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        RegisterMapper mapper = sqlSession.getMapper(RegisterMapper.class);
        User user = mapper.selectByName(name);
        //释放资源
        sqlSession.close();
        return user;
    }

    @Override
    public List<User> selectAllUser() {
        List<User> list=userDao.selectAllUser();
        return list;
    }

}
